package com.neu.his.controller.outpatientDoctorStation03;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neu.his.core.Result;
import com.neu.his.entity.Doctor;
import com.neu.his.entity.User;
import com.neu.his.entity.VO.outpatientDoctorStation03.DoctorData;
import com.neu.his.entity.VO.outpatientDoctorStation03.DoctorVO;
import com.neu.his.mapper.DoctorMapper;
import com.neu.his.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: neu-his
 * <p>
 * Created by 31316 on 2020/7/18 11:08
 */
@RestController
@RequestMapping("/doctor")
@Slf4j
public class OutpatientDoctorController {
    @Autowired
    DoctorMapper doctorMapper;

    @Autowired
    UserMapper userMapper;

    @GetMapping("/all")
    public Result getall() {
        QueryWrapper<Doctor> queryWrapper=new QueryWrapper<Doctor>();
        queryWrapper.ne("remove_mark",1);
        List<Doctor> list = doctorMapper.selectList(queryWrapper);
        DoctorVO doctorVO=new DoctorVO();
        doctorVO.setDoctors(new ArrayList<DoctorData>());
        for (Doctor doctor : list) {
            User user=userMapper.selectOne(new QueryWrapper<User>().eq("id",doctor.getOutpatientDoctorId()));
            log.info(JSON.toJSONString(user));
            if(user.getRemoveMark()!=1) {
                DoctorData doctorData=new DoctorData();
                doctorData.setDoctorName(user.getName());
                doctorData.setId(user.getId());
                doctorVO.getDoctors().add(doctorData);
            }
        }
        return Result.success(doctorVO);
    }
}
